package by.demchenko.sample.services.impl;

import by.demchenko.sample.dataaccess.base.FacultyDao;
import by.demchenko.sample.datamodel.Faculty;
import by.demchenko.sample.services.FacultyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

@Service
public class FacultyServiceImpl implements FacultyService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FacultyServiceImpl.class);

    @Inject
    private FacultyDao dao;

    @Override
    public Faculty get(Integer id) {
        return dao.getById(id);
    }

    @Override
    public void save(Faculty faculty) {
        dao.insert(faculty);
    }

    @Override
    public void saveOrUpdate(Faculty faculty) {
        if (faculty.getId() == null) {
            LOGGER.debug("Save new: {}", faculty);
            dao.insert(faculty);
        } else {
            LOGGER.debug("Update: {}", faculty);
            dao.update(faculty);
        }
    }

    @Override
    public void delete(Integer id) {
        dao.delete(id);
    }

    @Override
    public int getCount() {
        return dao.getCount();
    }

    @Override
    public List<Faculty> getAll() {
        return dao.getAll();
    }
}